package com.ruoyi.merchant.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.cg.dto.QueryPageBean;
import com.ruoyi.common.core.cg.pojo.Order;
import com.ruoyi.common.core.cg.result.PageResult;
import com.ruoyi.merchant.mapper.OrderMapper;
import com.ruoyi.merchant.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public int selectOrderByStatus(int leaderId) {
        return orderMapper.selectOrderByStatus(leaderId);
    }

    @Override
    public int selectOrderByStatus1(int leaderId) {
        return orderMapper.selectOrderByStatus1(leaderId);
    }

    @Override
    public PageResult selectOrderList(QueryPageBean queryPageBean) {
        //数据校验
        if (queryPageBean.getCurrentPage() == null || queryPageBean.getCurrentPage() <= 0){
            queryPageBean.setCurrentPage(1);
        }
        if (queryPageBean.getPageSize() == null){
            queryPageBean.setPageSize(5);
        }
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        List<Order> orderList = orderMapper.selectOrderList(queryPageBean.getLeaderId()
                ,queryPageBean.getReservedName(),queryPageBean.getReservedPhone(),queryPageBean.isFal());
        PageInfo<Order> pageInfo = new PageInfo<>(orderList);
        return new PageResult(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public List<Order> dtoList(Integer lid) {
        List<Order> dtoList = orderMapper.dtoList(lid);
        return dtoList;
    }

    @Override
    public List<Order> dtoListStatus(Integer lid) {
        List<Order> orderList = orderMapper.dtoListStatus(lid);
        return orderList;
    }
}

